{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$P(X=1,Y=1) = P(Y=1|X=1)*P(X=1) = P(X=1|Y=1)*P(Y=1)$$\n",
    "simple\n",
    "$$P(X,Y) = P(Y|X)*P(X)=P(X|Y)*P(Y)$$\n",
    "$$P(Y|X)=\\frac{P(X|Y)*P(Y)}{P(X)}$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$P(Y=1|X)=\\frac{P(X|Y=1)*P(Y=1)}{P(X)}=\\frac{P(x_{1},x_{2}....x_{n}|Y=1)*P(Y=1)}{P(x_{1},x_{2}....x_{n})}$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "分母继续分解采用如下 全概率公式\n",
    "$$P(X)=\\sum^{m}_{i=1}{P(y_{i})}*P(X|Y_{i})$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "ex:\n",
    "$$P(Y=1|X_{i}=零下,X_{2}=20天) =\\frac{P(x_{1},x_{2}|Y=1)*P(Y=1)}{P(x_{1},x_{2})}$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$P(冬眠|零下，20天)=\\frac{P(零下，20天|冬眠)*P(冬眠)}{P(零下，20天)}$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$P(冬眠|零下，20天)=\\frac{P(零下|冬眠)*P(20天|冬眠)*P(冬眠)}{P(冬眠)*P(零下，20天|冬眠)+P(不冬眠)*P(零下，20天|不冬眠)}$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "分子：\n",
    "$$P(冬眠) = \\frac{4}{11} P(零下|冬眠) = \\frac{4}{4}=1 𝑃(20天|冬眠) = \\frac{1}{4}$$\n",
    "分母：\n",
    "$$𝑃(零下，20天|冬眠) = \\frac{1}{4} 𝑃(不冬眠) = \\frac{7}{11} P(零下，20天|不冬眠)=\\frac{2}{7} $$ "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "最大后验估计只比较分子"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "积分公式\n",
    "$$\\int^{+\\infty}_{-\\infty}f(x)dx$$\n",
    "其中dx是f(x)在x上的积分"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "%load_ext watermark"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "charlie 2020-03-22 \n",
      "\n",
      "compiler   : Clang 9.0.1 \n",
      "system     : Darwin\n",
      "release    : 17.7.0\n",
      "machine    : x86_64\n",
      "processor  : i386\n",
      "CPU cores  : 4\n",
      "interpreter: 64bit\n"
     ]
    }
   ],
   "source": [
    "%watermark -a 'charlie' -d -m "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "from sklearn.naive_bayes import GaussianNB\n",
    "from sklearn.datasets import load_digits\n",
    "from sklearn.model_selection import train_test_split\n",
    "digits = load_digits() #手写数据集\n",
    "X, y = digits.data, digits.target"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9]\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAADS8AAACsCAYAAAAgl7jdAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjMsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+AADFEAAAgAElEQVR4nO3dfbRedXng/WsnIUACIhAJSoyAgSiptj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NlqLRSVRqdMz7jNDopDRaRpk+I+o0WqnPiX00WqDRKn1GaHQ682bzN+v7fmPXdX8cEZdGxNyI+Ezf92tmc4fHeVlEvDEivt913Xcn/t6pfd9fMqJ9KnlnRJw78SZyU0QcP+J9Zo1Gtxpj2WixPiM0Oh2NarQ6jY6+UX1OT6MarWws+4zQ6FZkLBst1meERqejUY1Wp9HRN6rP6WlUo9VpVKOV6XP0fUZodDoa1Wh1Gh19o/qcnkY1Wp1GNVrZWPYZodGtyFg2WqzPCI1OR6Ojb1Sf0yvRaNf3/Sh+XwAAAAAAAAAAAAAAAGAbN2fUCwAAAAAAAAAAAAAAAADbJoeXAAAAAAAAAAAAAAAAgEE4vAQAAAAAAAAAAAAAAAAMwuElAAAAAAAAAAAAAAAAYBAOLwEAAAAAAAAAAAAAAACDcHgJAAAAAAAAAAAAAAAAGITDSwAAAAAAAAAAAAAAAMAgHF4CAAAAAAAAAAAAAAAABvF/AbUPcYuIu9cQAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 4320x4356 with 20 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "max = 20\n",
    "plt.figure(figsize=(60, 60.5))\n",
    "for i in range(0,max):\n",
    "    img = X[i].reshape(-1,8)\n",
    "    plt.subplot(1,max,i+1)\n",
    "    plt.imshow(img)\n",
    "print(y[:max])\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[47,  0,  0,  0,  0,  0,  0,  1,  0,  0],\n",
       "       [ 0, 46,  2,  0,  0,  0,  0,  3,  6,  2],\n",
       "       [ 0,  2, 35,  0,  0,  0,  1,  0, 16,  0],\n",
       "       [ 0,  0,  1, 40,  0,  1,  0,  3,  4,  0],\n",
       "       [ 0,  0,  1,  0, 39,  0,  1,  4,  0,  0],\n",
       "       [ 0,  0,  0,  2,  0, 58,  1,  1,  1,  0],\n",
       "       [ 0,  0,  1,  0,  0,  1, 49,  0,  0,  0],\n",
       "       [ 0,  0,  0,  0,  0,  0,  0, 54,  0,  0],\n",
       "       [ 0,  3,  0,  1,  0,  0,  0,  2, 55,  0],\n",
       "       [ 1,  1,  0,  1,  2,  0,  0,  3,  7, 41]])"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Xtrain,Xtest,Ytrain,Ytest = train_test_split(X,y,test_size=0.3,random_state=420)\n",
    "gnb = GaussianNB().fit(Xtrain,Ytrain)\n",
    "#查看分数\n",
    "acc_score = gnb.score(Xtest,Ytest) #返回预测的精确性 accuracy\n",
    "#查看预测结果\n",
    "Y_pred = gnb.predict(Xtest)\n",
    "#查看预测的概率结果\n",
    "prob = gnb.predict_proba(Xtest)\n",
    "prob.shape #每一列对应一个标签类别下的概率\n",
    "prob[1,:].sum() #每一行的和都是一\n",
    "prob.sum(axis=1)\n",
    "from sklearn.metrics import confusion_matrix as CM\n",
    "CM(Ytest,Y_pred)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "Xtrain,Xtest,Ytrain,Ytest = train_test_split(X,y,test_size=0.3,random_state=420)\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
